import koa from 'koa';

// http请求成功
export class Success {
  public success: boolean;
  public data: any;
  public code: number;
  constructor(data?: any) {
    this.success = true;
    this.code = 200;
    this.data = data;
  }

  getSuccessBody(ctx: koa.Context) {
    ctx.body = this;
  }
}

export const SUCCESS = (ctx: koa.Context, data: any) => {
  return new Success(data).getSuccessBody(ctx);
};
